package com.qiang.androidinfo.Manager;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Build;
import android.provider.Settings;
import android.telephony.TelephonyManager;
import android.util.DisplayMetrics;

import com.qiang.androidinfo.AppContext;
import com.qiang.androidinfo.utils.SystemServiceUtils;

/**
 * Created by HP on 2016/9/3.
 */
public class MobileInfoManger {

    private static MobileInfoManger mInstance;
    private Context mContext;

    private MobileInfoManger() {
        mContext = AppContext.getContext();
    }


    public synchronized static MobileInfoManger getInstance() {
        if (mInstance == null) {
            mInstance = new MobileInfoManger();
        }
        return mInstance;
    }


    /**
     * 获得IMEI
     *
     * @return
     */
    public String getIMEI() {
        TelephonyManager telephonyManager = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
        String IMEI = telephonyManager.getDeviceId();
        return IMEI;
    }

    /**
     * 获得Android ID
     *
     * @return
     */
    public String getAndroidId() {
        String android_id = Settings.Secure.getString(mContext.getContentResolver(), "android_id");
        return android_id;
    }


    /**
     * 获得 Wifi Mac 地址
     *
     * @return
     */
    public String getWifiSSID() {
        WifiInfo wifiManager = ((WifiManager) mContext.getSystemService(Context.WIFI_SERVICE)).getConnectionInfo();

        String ssid = wifiManager.getSSID();

        return ssid;


    }


    /**
     * 获得 Wifi mac 地址
     *
     * @return
     */
    public String getWifiMac() {
        WifiInfo wifiManager = ((WifiManager) mContext.getSystemService(Context.WIFI_SERVICE)).getConnectionInfo();
        String macAddress = wifiManager.getMacAddress();
        return macAddress;

    }


    /**
     * 获得wifi b
     *
     * @return
     */
    public String getWifiBSSID() {
        WifiInfo wifiManager = ((WifiManager) mContext.getSystemService(Context.WIFI_SERVICE)).getConnectionInfo();
        String bssid = wifiManager.getBSSID();
        return bssid;
    }


    /**
     * 获得手机号码
     *
     * @return
     */
    public String getLineNumber() {

        TelephonyManager telephonyManager = SystemServiceUtils.getTelephonyManager(mContext);
        String line1Number = telephonyManager.getLine1Number();
        return line1Number;


    }


    /**
     * 获得sim序列号
     *
     * @return
     */
    public String getSimSerail() {
        TelephonyManager telephonyManager = SystemServiceUtils.getTelephonyManager(mContext);
        String subscriberId = telephonyManager.getSimSerialNumber();
        return subscriberId;


    }

    /**
     * sim 订阅ID
     *
     * @return
     */
    public String getSimSub() {
        TelephonyManager telephonyManager = SystemServiceUtils.getTelephonyManager(mContext);
        String subscriberId = telephonyManager.getSubscriberId();
        return subscriberId;

    }


    /**
     * SIM卡状态(5=就绪)
     *
     * @return
     */
    public int getSimStatus() {
        TelephonyManager telephonyManager = SystemServiceUtils.getTelephonyManager(mContext);
        int simState = telephonyManager.getSimState();
        return simState;
    }

    /**
     * 运营商id
     *
     * @return
     */
    public String getSimOperator() {
        TelephonyManager telephonyManager = SystemServiceUtils.getTelephonyManager(mContext);
        String simOperator = telephonyManager.getSimOperator();
        return simOperator;
    }


    /**
     * 运营商名称
     *
     * @return
     */
    public String getSimOperatorName() {
        TelephonyManager telephonyManager = SystemServiceUtils.getTelephonyManager(mContext);
        String simOperatorName = telephonyManager.getSimOperatorName();
        return simOperatorName;
    }

    /**
     * 获得国家吗
     *
     * @return
     */
    public String getSimCountryIso() {
        TelephonyManager telephonyManager = SystemServiceUtils.getTelephonyManager(mContext);

        String simCountryIso = telephonyManager.getSimCountryIso();

        return simCountryIso;


    }


    /**
     * 机型 MODEL
     *
     * @return
     */
    public String getBuildModel() {
        return Build.MODEL;
    }

    /**
     * 厂商
     *
     * @return
     */
    public String getManUfacturer() {
        return Build.MANUFACTURER;
    }

    /**
     * 手机制造商
     *
     * @return
     */
    public String getProduct() {
        return Build.PRODUCT;
    }


    /**
     * 硬件
     *
     * @return
     */
    public String getHardWare() {
        return Build.HARDWARE;
    }


    /**
     * 获得品牌
     *
     * @return
     */
    public String getBrand() {
        return Build.BRAND;
    }


    /**
     * 主板
     *
     * @return
     */
    public String getBoard() {
        return Build.BOARD;
    }

    /**
     * 系统启动程序版本号
     *
     * @return
     */
    public String getBootLoader() {
        return Build.BOOTLOADER;
    }


    /**
     * cpu指令集
     *
     * @return
     */
    public String getCPU() {
        return Build.CPU_ABI;
    }

    /**
     * cpu指令集2
     *
     * @return
     */
    public String getCPU2() {
        return Build.CPU_ABI2;
    }

    /**
     * 设置参数
     *
     * @return
     */
    public String getDevice() {
        return Build.DEVICE;
    }

    /**
     * 显示屏参数
     *
     * @return
     */
    public String getDisplay() {
        return Build.DISPLAY;
    }

    /**
     * 硬件识别码
     *
     * @return
     */
    public String getFingerPrint() {
        return Build.FINGERPRINT;
    }

    /**
     * HOST
     *
     * @return
     */
    public String getHost() {
        return Build.HOST;
    }


    /**
     * 获得基带版本
     *
     * @return
     */
    public String getRadioVersion() {
        return Build.getRadioVersion();
    }


    /**
     * 修订版本列表
     *
     * @return
     */
    public String getBuildId() {
        return Build.ID;
    }

    /**
     * 描述Build的time
     *
     * @return
     */
    public long getBuildTime() {
        return Build.TIME;
    }

    /**
     * 描述Build的time
     *
     * @return
     */
    public String getBuildTags() {
        return Build.TAGS;
    }

    /**
     * 描述Build的TYPE
     *
     * @return
     */
    public String getBuildType() {
        return Build.TYPE;
    }

    /**
     * 描述Build的USER
     *
     * @return
     */
    public String getBuildUser() {
        return Build.USER;
    }
    /**
     * Release
     *
     * @return
     */
    public String getRelease() {
        return Build.VERSION.RELEASE;
    }
    /**
     * sdkint
     *
     * @return
     */
    public int getSdkInt() {
        return Build.VERSION.SDK_INT;
    }
    /**
     * INCREMENTAL
     *
     * @return
     */
    public String getBuildIncremental() {
        return Build.VERSION.INCREMENTAL;
    }


    /**
     * INCREMENTAL
     *
     * @return
     */
    public int getDisplayDPI() {
        DisplayMetrics dm = getDisplayMetrics();
        return dm.densityDpi;
    }
    /**
     * width
     *
     * @return
     */
    public int getDisplayWidthP() {
        DisplayMetrics dm = getDisplayMetrics();
        return dm.widthPixels;
    }
    /**
     * width
     *
     * @return
     */
    public int getDisplayHeightP() {
        DisplayMetrics dm = getDisplayMetrics();
        return dm.heightPixels;
    }




    /**
     * 获得网络链接类型
     *
     * @return wifi:0  mobile:1 none:-1
     */
    public int getNetWorkType() {

        ConnectivityManager connectivityManager = SystemServiceUtils.getConnectivityManager(mContext);

        NetworkInfo info = connectivityManager.getActiveNetworkInfo();
        int type = info.getType();
        return type;

    }


    public DisplayMetrics getDisplayMetrics(){
        DisplayMetrics dm = mContext.getResources().getDisplayMetrics();
        return dm;
    }


    /**
     * 获得 系统详情
     *
     * @return
     */
    public String getInfo() {
        StringBuilder sb = new StringBuilder();
        sb.append("\n\n#基本信息");
        sb.append("\nAndroidID                 :").append(getAndroidId());
        sb.append("\nIMEI                 :").append(getIMEI());

        sb.append("\n\n#SIM卡信息");
        sb.append("\n手机号                 :").append(getLineNumber());
        sb.append("\nSim序列号(ICCID)              :").append(getSimSerail());
        sb.append("\nSim订阅ID(IMSI)              :").append(getSimSub());
        sb.append("\nSIM卡状态(5=就绪)            :").append(getSimStatus());
        sb.append("\n运营商ID                :").append(getSimOperator());
        sb.append("\n运营商名称                :").append(getSimOperatorName());
        sb.append("\n国家码               :").append(getSimCountryIso());

        sb.append("\n\n#屏幕信息");
        DisplayMetrics dm = getDisplayMetrics();
        sb.append("\n密度比                 :").append(dm.density);
        sb.append("\nDpi              :").append(dm.densityDpi);
        sb.append("\n高(像素)             :").append(dm.heightPixels);
        sb.append("\n宽(像素)            :").append(dm.widthPixels);
        sb.append("\n缩放因子(scaledDensity)                :").append(dm.scaledDensity);
        sb.append("\nxdpi                :").append(dm.xdpi);
        sb.append("\nydpi              :").append(dm.ydpi);

        sb.append("\n\n#编译信息");
        sb.append("\n机型(MODEL)            :").append(getBuildModel());
        sb.append("\n硬件制造商            :").append(getManUfacturer());
        sb.append("\n手机制造商            :").append(getProduct());
        sb.append("\n硬件(HARDWARE)            :").append(getHardWare());
        sb.append("\n品牌(BRAND)            :").append(getBrand());
        sb.append("\n主板            :").append(getBoard());
        sb.append("\nbootloader            :").append(getBootLoader());
        sb.append("\ncpu指令集            :").append(getCPU());
        sb.append("\ncpu指令集2            :").append(getCPU2());
        sb.append("\n设置参数           :").append(getDevice());
        sb.append("\n显示屏参数          :").append(getDisplay());
        sb.append("\n硬件识别码          :").append(getFingerPrint());
        sb.append("\n修订版本列表ID          :").append(getBuildId());
        sb.append("\nINCREMENTAL          :").append(Build.VERSION.INCREMENTAL);
        sb.append("\nRADIO          :").append(Build.RADIO);
        sb.append("\nRELEASE          :").append(Build.VERSION.RELEASE);
        sb.append("\n描述Build的标签          :").append(getBuildTags());
        sb.append("\nTIME          :").append(getBuildTime());
        sb.append("\nTYPE          :").append(getBuildType());
        sb.append("\nUSER          :").append(getBuildUser());
        sb.append("\nSDK_INT            :").append(Build.VERSION.SDK_INT);
        sb.append("\nSDK            :").append(Build.VERSION.SDK);
        sb.append("\nCODENAME            :").append("REL");


        sb.append("\n\nwifi跟Net信息\n");
        sb.append("\nWifi SSID               :").append(getWifiSSID());
        sb.append("\nWifi B-SSID              :").append(getWifiBSSID());
        sb.append("\nWifi Mac 地址             :").append(getWifiMac());
       // sb.append("\n网络类型             :").append(getNetWorkType()+"");


        return sb.toString();

    }


}
